home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2007 December / PCWKCD1207B.iso / Blogowanie poza sfera / Flock 0.9.1.3 stable / flock-0.9.1.3.en-US.win32.exe / flock / components / flockFlockHandler.js < prev    next >
Text File  |  2007-10-12  |  5KB  |  164 lines

  1. //
  2. // BEGIN FLOCK GPL
  3. // 
  4. // Copyright Flock Inc. 2005-2007
  5. // http://flock.com
  6. // 
  7. // This file may be used under the terms of of the
  8. // GNU General Public License Version 2 or later (the "GPL"),
  9. // http://www.gnu.org/licenses/gpl.html
  10. // 
  11. // Software distributed under the License is distributed on an "AS IS" basis,
  12. // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  13. // for the specific language governing rights and limitations under the
  14. // License.
  15. // 
  16. // END FLOCK GPL
  17. //
  18.  
  19. const CLASS_ID                = Components.ID("{7214FC64-FDA0-4DCD-B790-146265F8FA42}");
  20. const CLASS_NAME              = "Flock Protocol Handler";
  21. const CONTRACT_ID             = "@mozilla.org/network/protocol;1?name=flock";
  22.  
  23. function flockFlockHandler()
  24. {
  25. }
  26.  
  27. flockFlockHandler.prototype = {
  28.  
  29.   scheme: "flock",
  30.   defaultPort: -1,
  31.   protocolFlags: Components.interfaces.nsIProtocolHandler.URI_NORELATIVE | Components.interfaces.nsIProtocolHandler.URI_NOAUTH,
  32.   
  33.   allowPort: function(port, scheme)
  34.   {
  35.     return false;
  36.   },
  37.   
  38.   newChannel: function(URI)
  39.   {
  40.     var url = Components.classes["@mozilla.org/network/standard-url;1"].createInstance(Components.interfaces.nsIStandardURL);
  41.     url.init(Components.interfaces.nsIStandardURL.URLTYPE_STANDARD, -1, URI.spec, null, null);
  42.     url.QueryInterface(Components.interfaces.nsIURL);
  43.     
  44.     switch (url.host) {
  45.       case "favorites":
  46.         var chromeURL = "chrome://browser/content/flock/common/streamReader.xhtml";
  47.         break;
  48.       case "preview":
  49.         var chromeURL = "chrome://browser/content/flock/common/streamReader.xhtml";
  50.         break;
  51.       default:
  52.         var chromeURL = "chrome://browser/content/flock/common/streamReader.xhtml";
  53.         break;
  54.     }
  55.     
  56.     var ios = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService);
  57.     var channel = ios.newChannel(chromeURL, null, null);
  58.     
  59.     //var Channel = Components.Constructor("@flock.com/flock-channel;1", "flockIFlockChannel", "init");
  60.     //var channel = new Channel(URI);
  61.     
  62.     return channel;
  63.   },
  64.   
  65.   newURI: function(spec, originCharset, baseURI)
  66.   {
  67.     var url = Components.classes["@mozilla.org/network/simple-uri;1"].createInstance(Components.interfaces.nsIURI);
  68.  
  69.     try {
  70.       url.spec = spec;
  71.     } catch (e) {
  72.       try {
  73.         url.spec = this.scheme + ":" + spec;
  74.       } catch (e) {
  75.         url.spec = "javascript:void(0)";
  76.       }
  77.     }
  78.  
  79.     return url;
  80.   },
  81.  
  82.   // nsIClassInfo
  83.   getInterfaces: function(aCount)
  84.   {
  85.     var interfaces = [Components.interfaces.nsIProtocolHandler, Components.interfaces.nsIClassInfo];
  86.     aCount.value = interfaces.length;
  87.     return interfaces;
  88.   },
  89.  
  90.   // nsIClassInfo
  91.   getHelperForLanguage: function(aLanguage)
  92.   {
  93.     return null;
  94.   },
  95.  
  96.   // nsIClassInfo
  97.   contractID: CONTRACT_ID,
  98.  
  99.   // nsIClassInfo
  100.   classDescription: CLASS_NAME,
  101.  
  102.   // nsIClassInfo
  103.   classID: CLASS_ID,
  104.  
  105.   // nsIClassInfo
  106.   implementationLanguage: Components.interfaces.nsIProgrammingLanguage.JAVASCRIPT,
  107.  
  108.   // nsIClassInfo
  109.   flags: null,
  110.   
  111.   // nsISupports
  112.   QueryInterface: function(aIID)
  113.   {
  114.     if (!aIID.equals(Components.interfaces.nsISupports) && !aIID.equals(Components.interfaces.nsIProtocolHandler) && !aIID.equals(Components.interfaces.nsIClassInfo))
  115.       throw Components.results.NS_ERROR_NO_INTERFACE;
  116.     return this;
  117.   }
  118.  
  119. };
  120.  
  121. /******************************************************************************
  122.  * XPCOM Functions for construction and registration
  123.  ******************************************************************************/
  124. var Module = {
  125.   _firstTime: true,
  126.   registerSelf: function(aCompMgr, aFileSpec, aLocation, aType)
  127.   {
  128.     if (this._firstTime) {
  129.       this._firstTime = false;
  130.       throw Components.results.NS_ERROR_FACTORY_REGISTER_AGAIN;
  131.     }
  132.     aCompMgr = aCompMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
  133.     aCompMgr.registerFactoryLocation(CLASS_ID, CLASS_NAME, CONTRACT_ID, aFileSpec, aLocation, aType);
  134.   },
  135.  
  136.   unregisterSelf: function(aCompMgr, aLocation, aType)
  137.   {
  138.     aCompMgr = aCompMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
  139.     aCompMgr.unregisterFactoryLocation(CLASS_ID, aLocation);        
  140.   },
  141.   
  142.   getClassObject: function(aCompMgr, aCID, aIID)
  143.   {
  144.     if (!aIID.equals(Components.interfaces.nsIFactory))
  145.       throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
  146.     if (aCID.equals(CLASS_ID))
  147.       return Factory;
  148.     throw Components.results.NS_ERROR_NO_INTERFACE;
  149.   },
  150.  
  151.   canUnload: function(aCompMgr) { return true; }
  152. };
  153.  
  154. var Factory = {
  155.   createInstance: function(aOuter, aIID)
  156.   {
  157.     if (aOuter != null)
  158.       throw Components.results.NS_ERROR_NO_AGGREGATION;
  159.     return (new flockFlockHandler()).QueryInterface(aIID);
  160.   }
  161. };
  162.  
  163. function NSGetModule(aCompMgr, aFileSpec) { return Module; }
  164.